#ifndef GUI_MANAGER_H
#define GUI_MANAGER_H

#include "../Singleton.h"
#include "WidgetType.h"
#include "Widget.h"
#include <map>
#include <vector>
#include "../Include.h"

namespace PickinOpenSticks {
    namespace Ui {
        class Widget;

        /**
         * @author Adrian Tut
         * class Manager
         * Manages the ui widgets
         * @date 21/10/2010
         */
        class Manager : public Singleton<Manager> {
        public:
            typedef std::map<int, Widget*> WidgetList;

            void RegisterEvent(sf::Event* event);
            void AddWidget(const string& name, Widget* widget);
            void Initialize(sf::RenderWindow * renderTarget);
            void Update(int diff);
            Widget* FindWidgetByName(const std::string& name);

            sf::Vector2f ConvertCoords(int x, int y) {
                return window->ConvertCoords(x, y);
            }
            vector<Widget*> GetWidgetsByType(WidgetType type);

        private:
            WidgetList widgets; //holds the parent widgets
            int index; //used to keep track of focusing levels
            vector<sf::Event*> events;
            Widget* focus; //holds the currently focused widget if any
            sf::RenderWindow* window;
            core::Rectangle size;

            int hotSpotX, hotSpotY;
            bool drag;

            void SetHasFocus(WidgetList::reverse_iterator& i);
            void StartDrag(int hotSpotx, int hotSpoty);
            void StopDrag(int x, int y);


        };

        enum Alignment {
            Left = 0x00000001,
            Right = 0x00000010,
            Top = 0x00000100,
            Bottom = 0x00001000,
            CenterHorizontal = 0x00000011, //Left | Right
            CenterVertical = 0x00001100, //Top  | Down
            Center = 0x00001111, //Top | Down | Left | Right
            LeftBottom = 0x00001001, //Left | Bottom
            RightBottom = 0x00001010,
            LeftTop = 0x00000101,
            RightTop = 0x00000110,
            None = 0

        };
    }
}

#endif
